#!/usr/bin/python
# -*- coding: UTF-8 -*-

# new class tag
__metaclass__=type

class Student:
	def studentName(self, name):
		print 'My name is %s' % name

	def length_message(x):
	 	print 'The length of %s is %s ' % (repr(x), len(x))

class Teacher:
	def teacher(self, name):
		print 'Teacher name is %s' % name

class Secretive:
	def __inaccessible(self):
		print "bet you can't see me"

	def accessible(self):
		print "The secret message is:"
		self.__inaccessible()

class MemberCounter:
	members = 0
	def init(self):
		print 'self is %s' % repr(self)
		MemberCounter.members += 1


# --------------------以下为类的实现-------------------------
s = Student()
s.studentName('Tony')
print s
print type(s)
print s.__class__

t = Teacher()
t.teacher('Jim')
print t
print type(t)
print t.__class__

se = Secretive()
se.accessible()
try:
	se.__inaccessible()
except:
	print "__inaccessible error:"

m1 = MemberCounter()
m1.init()
print m1, MemberCounter.members

m2 = MemberCounter()
m2.init()
print m2, MemberCounter.members

# 类对象绑定函数
def func(x):print '%s name is func' % x
m1.mem = func
m1.mem('new func')

# m1.newIstance = ‘hello’这句话的意思是创建一个对象hello, 在对象a的命名空间中，
# 创建一个变量来绑定这个‘hello’，newIstance就属于a对象的命名空间了，不属于类。
# http://blog.csdn.net/maopaopao2087/article/details/41115963
m1.newIstance = 'hello'
print m1.newIstance

# 定义超类

class Filter:
	def init(self):
		self.blocked = []

	def filter(self, sequence):
		return [x for x in sequence if x not in self.blocked]

class SPAMFilter(Filter):
	def init(self):
		self.blocked = ['SPAM']
# 父类
f = Filter()
f.init()
print f.filter([1,2,3])
print f.filter('123')

# 子类
sp = SPAMFilter()
sp.init()
print sp.filter(['SPAM','SPAM','SPAM','peant','egg','bacon','SPAM' ])

# 调查继承





























